public class Solution2 {
    static class ListNode {
        public int val;
        public ListNode next;
    }

    //判断回文链表
    public boolean isPail (ListNode head) {
        // write code here
        if(head == null){
            return true;
        }
        ListNode slow = head;
        ListNode fast = head;
        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }
        ListNode left = head;
        ListNode right = reverse(slow);
        while(right != null){
            if(left.val != right.val){
                return false;
            }else {
                left = left.next;
                right = right.next;
            }
        }
        return true;
    }

    //相当于直接把后半部分断开了
    private ListNode reverse(ListNode head) {
        ListNode prev = null;
        ListNode cur = head;
        while (cur != null) {
            ListNode curN = cur.next;
            cur.next = prev;
            prev = cur;
            cur = curN;
        }
        return prev;
    }

}
